Home | | Latest | About | Random
# Experiments.
Weird experiments to try but don't sweat it.
**EXPERIMENTATION TIME.** Which of the following commented line, when uncommented, will give a build error? Note this behavior is specific for `int` types. It is possible to design our own type where all of these will be "allowed".
```cpp
// Do not sweat this.
int main(){
int x = 5;
// (x++) = 10;
// (++x) = 10;
// (x++)++;
// ++(x++);
// (++x)++;
// ++(++x);
return 0;
}
```
- Mystery: 17/20 prints `0`, 20/20 prints `100`.
- `17 / 5` is 3, `17 % 5` is 2.
- Example F with `day = 5` (Friday): +3 is Monday (1); +10 is Monday (1); +3000 is Tuesday (2); 3000 days is 428 weeks.
- Precision demo: `0.10000000000000001`, `0.29999999999999999`, `0.30000000000000004`.
- Task A: `static_cast(correct) / total * 100`.
- Task B: `double score = static_cast(correct) / total * 100;` then `cout << round(score * 10) / 10;` (7 of 9 gives 77.8).
- Example D: `0`, `1`, then `1`, `1`.
- Cut from this version: negative `/` and `%` (Example E, answers -6, 2, -6, -2) and the `INT_MAX + 1` demo. Both are covered by the section 5 reading.